namespace Outcoder.UI.Xaml.Renderers
{
	class AppBarItemPropertyResolver
	{
		internal static bool TryGetItemText(IAppBarItem appBarItem, out string text)
		{
			bool resolvedText = false;

			text = appBarItem.Text;

			if (!string.IsNullOrEmpty(text))
			{
				resolvedText = true;
			}
			else
			{
				var commandItem = appBarItem as AppBarItem;
				if (commandItem != null && commandItem.Command != null)
				{
					var uiCommand = commandItem.Command as IUICommand;
					if (uiCommand != null)
					{
						text = uiCommand.Text;
						resolvedText = true;
					}
				}
			}

			return resolvedText;
		}

		internal static bool TryGetItemUrl(IAppBarItem appBarItem, out string url)
		{
			bool resolveValue = false;

			var uri = appBarItem.IconUri;

			if (uri == null)
			{
				url = null;
			}
			else
			{
				url = uri.OriginalString;
			}

			if (string.IsNullOrEmpty(url))
			{
				var commandItem = appBarItem as AppBarItem;
				if (commandItem != null && commandItem.Command != null)
				{
					var uiCommand = commandItem.Command as IUICommand;
					if (uiCommand != null)
					{
						url = uiCommand.IconUrl;
						if (!string.IsNullOrWhiteSpace(url))
						{
							resolveValue = true;
						}
					}
				}
			}

			return resolveValue;
		}

	}
}